package com.sumainfor.wx.tenant.controller;

import com.sumainfor.common.util.FieldCheckUtil;
import com.sumainfor.common.util.JsonResult;
import com.sumainfor.common.utlis.Pager;
import com.sumainfor.wx.tenant.feign.OperationsFeignClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * 功能描述:
 * 账单支付
 * @Auther: zhlu
 * @Date: 2019/3/24 13:37
 * @Description:
 */
@RestController
@RequestMapping("/bill")
public class BillController {

    @Autowired
    OperationsFeignClient GmioFeignClient;

    /**
     * 功能描述: 
     * 根据合同编号获取当前租客首月房租账单
     * @Author zhlu
     * @Description //TODO
     * @Date 2019/3/24 13:41
     */
    @GetMapping("/getFirsMonRent")
    public JsonResult getFirsMonRent(@RequestParam Map<String,Object> params){
        JsonResult<Map<String, Object>> jsonResult = GmioFeignClient.getFirsMonRent(params);
        if (jsonResult.isSuccess() == false) {
            return jsonResult;
        }
        return jsonResult;
    }

    /**
     * 功能描述:
     * 支付完成验证与操作
     * @Author zhlu
     * @Description //TODO
     * @Date 2019/3/27 15:01
     */
    @ResponseBody
    @PostMapping("/PaymentCompleted")
    public JsonResult PaymentCompleted(@RequestBody Map<String,Object>params){
        JsonResult<Map<String, Object>> jsonResult = GmioFeignClient.PaymentCompleted(params);
        if (jsonResult.isSuccess() == false) {
            return jsonResult;
        }
        return jsonResult;
    }

    /**
     * 功能描述: 
     * 支付宝转账
     * @Author zhlu
     * @Description //TODO
     * @Date 2019/3/29 21:06
     */
    @ResponseBody
    @PostMapping("/PayOffline")
    public JsonResult PayOffline(@RequestBody Map<String,Object>params){
        JsonResult<Map<String, Object>> jsonResult = GmioFeignClient.PayOffline(params);
        if (jsonResult.isSuccess() == false) {
            return jsonResult;
        }
        return jsonResult;
    }

    /**
     * 功能描述: 
     * 根据租客编号和出租类型获取租客所有账单
     * @Author zhlu
     * @Description //TODO
     * @Date 2019/4/4 21:57
     */
    @GetMapping("/getBillAllList")
    public JsonResult getBillAllList(@RequestParam Map<String,Object> params,Pager pager){
        if(!FieldCheckUtil.isMapFieldNotNull(params,new String[]{"TenId"})){
            return  JsonResult.error("TenId不能为空！");
        }
//        if(!FieldCheckUtil.isMapFieldNotNull(params,new String[]{"Payment"})){
//            return  JsonResult.error("Payment不能为空！");
//        }
        JsonResult<Map<String, Object>> jsonResult = GmioFeignClient.getBillAllList(params,pager);
        if (jsonResult.isSuccess() == false) {
            return jsonResult;
        }
        return jsonResult;
    }


    /**
     * 功能描述: 
     * 根据账单编号和租客编号获取账单详情
     * @Author zhlu
     * @Description //TODO
     * @Date 2019/4/6 15:59
     */
    @GetMapping("/getBillAllBiIdMap")
    public JsonResult getBillAllBiIdMap(@RequestParam Map<String,Object>params){
        JsonResult<Map<String, Object>> jsonResult = GmioFeignClient.getBillAllBiIdMap(params);
        if (jsonResult.isSuccess() == false) {
            return jsonResult;
        }
        return jsonResult;
    }

    /**
     * 功能描述: 
     * 根据合同编号获取账单
     * @Author zhlu
     * @Description //TODO
     * @Date 2019/4/15 19:25
     */
    @PostMapping("/getBillFeeMapFile")
    public JsonResult getBillFeeMapFile(@RequestBody Map<String,Object>params){
        JsonResult<Map<String, Object>> jsonResult = GmioFeignClient.getBillFeeMapFile(params);
        if (jsonResult.isSuccess() == false) {
            return jsonResult;
        }
        return jsonResult;
    }

    /**
     * 功能描述: 
     * 支付宝水电燃支付，审核之后重新支付
     * @Author zhlu
     * @Description //TODO
     * @Date 2019/4/16 14:36
     */
    @PostMapping("/UpdateBillPay")
    public JsonResult UpdateBillPay(@RequestBody Map<String,Object>params){
        JsonResult<Map<String, Object>> jsonResult = GmioFeignClient.UpdateBillPay(params);
        if (jsonResult.isSuccess() == false) {
            return jsonResult;
        }
        return jsonResult;
    }



}
